package DesignPatern.A18_备忘录模式.A01_基本模式;

/**
 * @Author: Du
 * @Date: 2021/8/3 14:52
 */
public class Originator
{
    private String state = "";
    
    public String getState()
    {
        return state;
    }
    
    public void setState(String state)
    {
        this.state = state;
    }
    
    public IMemento createMemento()
    {
        return new Memento(this.state);
    }
    
    public void restoreMemento(IMemento memento)
    {
        this.setState(((Memento) memento).getState());
    }
    
    private class Memento implements IMemento
    {
        private String state = "";
        
        private Memento(String state)
        {
            this.state = state;
        }
        
        public String getState()
        {
            return state;
        }
        
        public void setState(String state)
        {
            this.state = state;
        }
    }
}
